<?php

/**
 * Enter description here ...
 * @author Kevin
 * @version 1.0
 * @created 12-d�c.-2011 19:51:41
 */
class Publication extends Date implements I_Persistent
{

	/**
	 * variable indiquant si la publication existe en base
	 */
	var $exist = false;
	/**
	 * ================================================================== Data
	 * ==================================================================
	 */
	var $id;
	var $concretid;
	var $language;
	var $owner;
	var $type;
	var $visibility;


	/**
	 * Enter description here ...
	 * @param string $pType : EVENT, COMMENT, etc.
	 * @param int $pId : ID concret de la publication à créer
	 * 
	 * @param pType
	 * @param pId
	 */
	function Publication($pType, $pId)
	{
		global $wpdb;
		
		// valeur par defaut
		$this->concretid = $pId;
		$this->type = $pType;
		$this->date = date("Y-m-d");
		$this->hour = date("H:i:s");
		$this->language = 1;	// anglais
		$this->owner = 0;	// personne
		$this->visibility = 0;	// tout le monde
		
		$_row =
		$wpdb->get_row(
			$wpdb->prepare(
				// request
				"SELECT * 
				FROM publications 
				WHERE fk_concretid = %d 
				AND type = '%s'",
				
				// params
				$pId,
				$pType
			)
		);
		
		
		$this->id = $_row->id;
		if($_row->id > 0 ){
			$this->owner = $_row->fk_owner;
			$this->visibility = $_row->fk_visibility;
			$this->date = $_row->date;
			$this->hour = $_row->hour;
			$this->language = $_row->fk_language;
		
			$this->exist = true;
		}
	}

	function createNotification()
	{
	}

	/**
	 * Enter description here ...
	 * @return boolean
	 */
	function getExist()
	{
		return $this->exist;
	}

	/**
	 * @return identifiant concret de la publication (event, comment, ...)
	 */
	public function setId($id)
	{
	    $this->concretid = $concretid;
	}
	
	public function getId()
	{
	    return $this->concretid;
	}

	/**
	* @return identifiant de la publication
	*/
	public function setPublicationId($id)
	{
	    $this->id = $id;
	}
	
	public function getPublicationId()
	{
	    return $this->id;
	}
	
	/**
	 * Enter description here ...
	 */
	function getLanguage()
	{
		return $this->language;
	}

	function getOwner()
	{
		return new User($this->owner);
	}

	public function setType($type)
	{
	    $this->type = $type;
	}
	
	public function getType()
	{
	    return $this->type;
	}

	function getUsersToNotify()
	{
		
	}

	/**
	 * Enter description here ...
	 */
	function getVisibility()
	{
		return $this->visibility;
	}

	/**
	 * Enter description here ...
	 */
	function toHTML()
	{
	}

	function create()
	{
		global $wpdb;
		$queryTable = 'publications';
		$queryData = array( 
					'fk_owner' => $this->owner,
					'type' => $this->type,
					'fk_concretid' => $this->id,
					'fk_visibility' => $this->visibility,
					'date' => $this->date,
					'hour' => $this->hour,
					'fk_language' => $this->language
		);
		$queryDataFormat = array('%d','%s','%d','%d','%s','%s','%d');		
		$wpdb->insert( $queryTable, $queryData, $queryDataFormat);
		
	}

	function save()
	{
	}

	function delete()
	{
	}

}
?>